package com.hualan.sfzy.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzy.constant.CommonConstant;
import com.hualan.sfzy.entity.system.Role;
import com.hualan.sfzy.mapper.system.RoleMapper;
import com.hualan.sfzy.service.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName RoleServiceImpl
 * @Description TODO
 * @Author Mindy
 * @Date 2025年07月09日 下午8:56
 * @Version 1.0
 */
@Service("roleService")
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public int add(com.hualan.sfzy.entity.system.Role role) {
        return roleMapper.insert(role);
    }

    @Override
    public int remove(Integer id) {
        return roleMapper.delete(id);
    }

    @Override
    public int removeBatch(Integer[] ids) {
        return roleMapper.deleteBatch(ids);
    }

    @Override
    public int edit(com.hualan.sfzy.entity.system.Role role) {
        return roleMapper.update(role);
    }

    @Override
    public Role findById(Integer id) {
        return roleMapper.selectById(id);
    }

    @Override
    public Map<String, Object> findByPage(Integer pageNum, Integer pageSize, Role role) {
        PageHelper.startPage(pageNum, pageSize);

        List<Role> list = roleMapper.select(role);

        PageInfo<Role> pageInfo = new PageInfo<>(list);

        Map<String, Object> map = new HashMap<>();

        map.put(CommonConstant.PAGE_LIST, list);
        map.put(CommonConstant.PAGE_TOTAL, pageInfo.getPages());
        map.put(CommonConstant.TOTAL, pageInfo.getTotal());

//        map.put("list", list);
//        map.put("total", pageInfo.getTotal());
//        map.put("pages", pageInfo.getPages());

        return map;
    }

    @Override
    public List<Role> find() {
        return roleMapper.select(null);
    }
}
